//@version: $Id: Map.h 146 2010-12-09 01:30:28Z beermanforlife $

#pragma once

#include "StopWatch.h"
#include <assert.h>
#include "Global.h"
#include "templatevector.h"

#include "Shape.h"
#include "UserInput.h"

/*
Authors:
   Jared Bills
   Matthew Morrill
   John Parks
*/
//The world map for bejeweled
class Map {
private:
	/*Author: Jared Bills*/
	//Grid of shapes as the map
	Shape m_vGrid[HEIGHT][WIDTH];
	/*Author: Jared Bills*/
	//Combo list
	TemplateVector<Combo> m_vMarkedCombos;
	/*Author: Jared Bills*/
	//Input buffer
	UserInput m_vClickBuffer[CLICK_MAX];
	//Current click to track for input
	unsigned int m_uiCurrentClick;
	// this is the stopwatch object that will be used for updates to drawn objects
	StopWatch* g_pStopWatch; 

	//will be used as a toggle within the spin all
	bool rotateState;

	
	/*Author: Jared Bills*/
	//Clears the combo list
	inline void clear();
	/*Author: Jared Bills*/
	//Swaps two shapes whith the specified coordinates, returns true if successful
	inline const bool swapQuick(const unsigned int &, const unsigned int &, const unsigned int &, const unsigned int &);
	/*Author: Jared Bills*/
	//Checks if there are three shapes close together horizontally or vertically anywhere on the grid and returns true if so
	//   Note: Also keeps track of the combos in the combo list (to be cleared with clear() later)
	inline const bool comboCheck();
	/*Author: Jared Bills*/
	//Checks if there are three shapes close together horizontally or vertically anywhere on the grid and returns true if so
	inline const bool comboCheckQuick();
	/*Author: Jared Bills*/
	//Uses the recorded two clicks to swap a given shape
	inline void handleClickInput();
public:
	//Constructor
	Map();
	//Destructor
	~Map();
	/*Author: John Parks*/
	//Initiates the map and returns true if successful
	//   Note: To be called following object instantiation
	const bool init();
	/*Author: Jared Bills*/
	//Swaps two shapes whith the specified coordinates and sets shapes to swap for display, returns true if successful
	const bool swap(const unsigned int &, const unsigned int &, const unsigned int &, const unsigned int &);
	/*Author: Jared Bills*/
	//Checks all possible swap combinations on the map and returns false if there are none left (game over)
	//   Note: Call comboRenew() prior to this
	const bool check();
	/*Author: Matthew Morrill*/
	//Fills the map with new shapes to take the place of void combos
	void fill();
	/*Author: Jared Bills*/
	//Checks map for combos (without swapping), keeps track of them, and replaces those with new shapes, and returns true if combos were found and replaced
	//   Note: To be called prior to check()
	const bool comboRenew();
	/*Author: Matthew Morrill*/
	//Handles the input gotten from the UserInput class. It will track number of clicks, where, and decide when to swap.
	//   Note: Also should be able to handle keyboard presses
	void handleInput(UserInput);
	/*Author: John Parks*/
	//Draws all the shapes and background grid
	void drawAll();
	/*Author: Matthew Morrill*/
	//Goes through the map array and rotates all of them.
	void spinAll();
	/*Author: Matthew Morrill*/	
	//Gets the Shape at the current location of the mouse.	
	Shape getShapeAt(UserInput);
	//Gets pointer to the Shape at the given location
	Shape& getShapeAt(Location& a_loc);
	//reset to not call the init and cause all files to be reloaded too many times
	void resetMap();
};